package ua.zwpp.java8.concurrency;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

/**
 * Created by vitaly on 17.09.14.
 */
public class LongAccumulatorDemo {

    public static void main(String[] args) {
        case1();
        case2();
    }

    private static void case2() {
        LongAdder a = new LongAdder();

        a.add(4);
        a.add(6);
        a.add(8);

        System.out.println("via LongAdder ____" + a.longValue());
    }

    private static void case1() {
        LongAccumulator acc = new LongAccumulator((a, b) -> a + b, 0);

        acc.accumulate(4);
        acc.accumulate(6);
        acc.accumulate(8);

        System.out.println("via LongAccumulator ____" + acc.longValue());
    }
}
